package com.xc.content.controller;

import com.xc.base.model.PageParams;
import com.xc.base.model.PageResult;
import com.xc.content.model.dto.AddCourseDto;
import com.xc.content.model.dto.CourseBaseInfoDto;
import com.xc.content.model.dto.EditCourseDto;
import com.xc.content.model.dto.PageQueryCourseParamsDto;
import com.xc.content.model.po.CourseBase;
import com.xc.content.service.CourseBaseService;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@RestController
@Api(tags = "课程信息相关接口")
@Slf4j
@AllArgsConstructor
public class CourseBaseController {
    private final CourseBaseService courseBaseService;

    @ApiOperation("课程信息分页查询")
    @PostMapping("/course/list")
    public PageResult<CourseBase> list(PageParams pageParams, @RequestBody(required = false) PageQueryCourseParamsDto pageQueryCourseParamsDto) {
        log.info("课程信息分页查询:{}", pageParams);
        return courseBaseService.pageQuery(pageParams, pageQueryCourseParamsDto);
    }

    /**
     * Validated 激活参数校验
     * ValidationGroups 分组校验
     *
     * @param addCourseDto
     * @return
     */
    @ApiOperation("新增课程基础信息")
    @PostMapping("/course")
    public CourseBaseInfoDto createCourseBase(@RequestBody @Validated AddCourseDto addCourseDto) {
        log.info("新增课程基础信息:{}", addCourseDto);
        return courseBaseService.createCourseBase(1232141425L, addCourseDto);
    }


    @ApiOperation("查询课程信息详情")
    @GetMapping("/course/{courseId}")
    public CourseBaseInfoDto queryCourseBase(@PathVariable("courseId") Long courseId) {
        log.info("查询课程信息详情:{}", courseId);
        return courseBaseService.queryCourseBase(courseId);
    }


    @ApiOperation("修改课程基础信息")
    @PutMapping("/course")
    public CourseBaseInfoDto editCourseBase(@RequestBody @Validated EditCourseDto editCourseDto) {
        log.info("修改课程基础信息:{}", editCourseDto);
        return courseBaseService.editCourseBase(editCourseDto);
    }

    @ApiOperation("删除课程")
    @DeleteMapping("/course/{id}")
    public void delCourseBase(@PathVariable("id") Long id) {
        log.info("删除课程:{}", id);
        courseBaseService.removeById(id);
    }

    @ApiOperation("提交审核")
    @PostMapping("/courseaudit/commit/{id}")
    public void commit(@PathVariable("id") Long id) {
        log.info("提交审核:{}", id);
        courseBaseService.commit(id);
    }


}
